package com.insurance.controller;


import com.insurance.common.ResultData;
import com.insurance.pojo.DriverEvaluation;
import com.insurance.pojo.SensitiveWords;
import com.insurance.service.DriverEvalService;
import com.insurance.utils.ConversionDateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: drc
 * Date: 2020/10/26 16:26
 * Description:
 * Version: V1.0
 */
@Controller
@RequestMapping(value = "/eval")
@Api(value = "评价信息",tags = "评价数据接口API")
public class DriverEvalController {
    @Autowired
    private DriverEvalService driverEvalService;

    @RequestMapping(value = "/addDriverEvaL.do",method = RequestMethod.POST)
    @ApiOperation(value = "添加司机评价信息接口",notes = "根据提交信息添加司机评价",httpMethod = "post", response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="添加成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResultData addDriverEval(@RequestBody DriverEvaluation driverEvaluation){
        ResultData resultData = new ResultData();
        int result =  driverEvalService.addDriverEval(driverEvaluation);
//        int result=1;
        if(result > 0){
            resultData.setCode(200);
            resultData.setMsg("添加成功");
            return resultData;
        }else {
            resultData.setCode(500);
            resultData.setMsg("添加失败");
            return resultData;
        }

    }
    @RequestMapping(value = "/delDriverEvaL.do",method = RequestMethod.GET)
    @ApiOperation(value = "删除司机评价信息接口",notes = "根据提交信息删除司机评价",httpMethod = "get", response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="删除成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResultData delDriverEval(Integer id){
        System.out.println("=========================="+id);
        ResultData resultData= new ResultData();
        int result =  driverEvalService.delDriverEval(id);
        if(result > 0){
            resultData.setCode(200);
            resultData.setMsg("删除成功");
        }
        return resultData;
    }

    @RequestMapping(value = "/findDriverEvaL.do",method = RequestMethod.GET)
    @ApiOperation(value = "查询司机评价信息接口",notes = "根据提交信息查询司机评价",httpMethod = "get", response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResultData findDriverEval(String string,String string2,String orderTime,String orderTimeEnd,Integer userId){
        ResultData resultData= new ResultData();
        List<Map> mapList=driverEvalService.findDriverEval(string,string2,orderTime,orderTimeEnd,userId);
        for (Map map:mapList){
            if (map.get("evaluate_time")!=null){
                map.put("evaluate_time", ConversionDateUtils.conversionDateStringUtils(map.get("evaluate_time")));
            }
        }
        resultData.setCode(200);
        resultData.setMsg("查询成功");
        resultData.setData(mapList);
        return resultData;
    }
    @RequestMapping(value = "/querySensitiveWords.do",method = RequestMethod.GET)
    @ApiOperation(value = "查询敏感词信息接口",notes = "根据提交信息查询敏感词",httpMethod = "get", response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResultData querySensitiveWords(){
        ResultData resultData = new ResultData();
        List<Map> mapList=driverEvalService.querySensitiveWords();
            resultData.setCode(200);
            resultData.setMsg("查询成功");
            resultData.setData(mapList);
            return resultData;
    }
    @RequestMapping(value = "/updateSensitiveWords.do",method = RequestMethod.GET)
    @ApiOperation(value = "修改敏感词信息接口",notes = "根据提交信息修改敏感词",httpMethod = "get", response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="修改成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResultData updateSensitiveWords(String sensitive_words){
        ResultData resultData = new ResultData();
        int result=driverEvalService.updateSensitiveWords(sensitive_words);
//        int result=1;
        if(result>0){
            resultData.setCode(200);
            resultData.setMsg("修改成功");
            return resultData;
        }else{
            resultData.setCode(500);
            resultData.setMsg("修改失败");
            return resultData;
        }
    }
}
